/*
 * CTerrain.h
 *
 *  Created on: Oct 4, 2011
 *      Author: welcome
 */

#ifndef CTERRAIN_H_
#define CTERRAIN_H_

#include <GLES/gl.h>
#include <gg2d/gg2d.h>
#include <KD/kd.h>
#include <stdio.h>

namespace GGEngine {

using namespace std;

class CTerrain {
public:
	CTerrain(gg2D* agg2D);
	virtual ~CTerrain();
	/*
	 * Render
	 */
	void render();
	/*
	 * Load height map
	 */
	KDint loadHeightMap(const char * const fileName, GLfloat xzstep,
			GLfloat ystep);
	/*
	 * Reset height map
	 */
	GLvoid resetHeightMap();

	GLfloat position[3];

private:

	/**
	 * The position of the terrain
	 */
	/**
	 * Flag, if height map is available
	 */
	GLboolean heightMapAvailable;
	/**
	 * Width (and height) of the terrain
	 */
	GLuint heightMapWidth;

	/**
	 * The indices, which build the terrain
	 */
	GLushort* vertexIndices;
	/**
	 * The local vertices
	 */
	GLfloat* localVertices;
	/**
	 * Flag, if texture is available
	 */
	GLboolean textureMapAvailable;
	/**
	 * The texture coordinates
	 */
	GLfloat* texCoord;
	/**
	 * Texture name of the texture
	 */
	GLuint textureMapName;
	/**
	 * Flag, if detail texture is available
	 */
	GLboolean detailTextureAvailable;

	/**
	 * The texture coordinates of the detail map
	 */
	GLfloat* detailTexCoord;

	/**
	 * Texture name of the detail texture
	 */
	GLuint detailTextureName;

	/*
	 *  Height Map
	 */
	gg2DRawImage* heightMap;

	gg2DAllocator * aAllocator;

	/**
	 * Scaling of the xz axis
	 */
	GLfloat xzscale;

	/*
	 * gg2D property
	 */
	gg2D* agg2D;
};
}
#endif /* CTERRAIN_H_ */
